import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import Path from 'path'

function Resolve(url){
  return Path.resolve(__dirname,url);
}

// https://vitejs.dev/config/
export default defineConfig(
  ({command, mode,})=>{
    //本地开发
    if(command=="serve"){
      return {
        //配置路径
        base:"",
        envDir:"./config",
        resolve: {
          alias: {
            "@": Resolve("./src"),
            "@views":Resolve("./src/views"),
            "@components": Resolve("./src/components"),
            "@utils": Resolve("./src/utils"),
            "@network": Resolve("./src/network"),
          },
        },
        server: {
          open: true,
          host: "127.0.0.1",
          port:8080,
          proxy:{
             /*服务器代理*/
          }
        },
        plugins: [react()],
      }
    }
    else if(command=="build"){
      return {
        //配置路径
        base:"",
        envDir:"./config",
        resolve: {
          alias: {
            "@": Resolve("./src"),
            "@views":Resolve("./src/views"),
            "@components": Resolve("./src/components"),
            "@utils": Resolve("./src/utils"),
            "@network": Resolve("./src/network"),
          },
        },
        server: {
          open: true,
          host: "127.0.0.1",
          port:8080,
        },
        plugins: [react()],
      }
    }
    
  }

)
